﻿'Nhiệm vụ: Quản lý người sử dụng hệ thống FMS
'
'
'
Option Strict On
Option Explicit On 

Imports IP.Core.IPCommon
Imports IP.Core.IPSystemAdmin
Imports IP.Core.IPUserService
Imports IP.Core.IPException
Imports IP.Core.IPData
Imports IP.Core.IPDataControl
Imports IP.Core.IPData.IPDBName
Imports System.Windows.Forms
Imports C1.Win.C1FlexGrid


Class f114_quan_ly_user
    Inherits System.Windows.Forms.Form
    Implements I_DisplayableInPanel

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        format_controls()
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents imageList As System.Windows.Forms.ImageList
    Friend WithEvents m_panel As System.Windows.Forms.Panel
    Friend WithEvents m_cmd_xoa As SIS.Controls.Button.SiSButton
    Friend WithEvents m_cmd_thoat As SIS.Controls.Button.SiSButton
    Friend WithEvents m_stb_fms_style As System.Windows.Forms.StatusBar
    Friend WithEvents m_stMess As System.Windows.Forms.StatusBarPanel
    Friend WithEvents m_stUser As System.Windows.Forms.StatusBarPanel
    Friend WithEvents m_cmd_them_moi As SIS.Controls.Button.SiSButton
    Friend WithEvents m_panel_main As System.Windows.Forms.Panel
    Friend WithEvents m_fg As C1.Win.C1FlexGrid.C1FlexGrid
    Friend WithEvents m_lbl_info As System.Windows.Forms.Label
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents m_lbl_last_updated_user As System.Windows.Forms.Label
    Friend WithEvents m_lbl_last_updated_date As System.Windows.Forms.Label
    Friend WithEvents m_lbl_created_date As System.Windows.Forms.Label
    Friend WithEvents m_lbl_created_user As System.Windows.Forms.Label
    Friend WithEvents m_txt_date_created As System.Windows.Forms.TextBox
    Friend WithEvents m_txt_last_updated_user As System.Windows.Forms.TextBox
    Friend WithEvents m_txt_user_created As System.Windows.Forms.TextBox
    Friend WithEvents m_txt_last_updated_date As System.Windows.Forms.TextBox
    Friend WithEvents m_cmd_chi_tiet As SIS.Controls.Button.SiSButton
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(f114_quan_ly_user))
        Me.imageList = New System.Windows.Forms.ImageList(Me.components)
        Me.m_panel = New System.Windows.Forms.Panel
        Me.m_cmd_them_moi = New SIS.Controls.Button.SiSButton
        Me.m_cmd_chi_tiet = New SIS.Controls.Button.SiSButton
        Me.m_cmd_xoa = New SIS.Controls.Button.SiSButton
        Me.m_cmd_thoat = New SIS.Controls.Button.SiSButton
        Me.m_stb_fms_style = New System.Windows.Forms.StatusBar
        Me.m_stMess = New System.Windows.Forms.StatusBarPanel
        Me.m_stUser = New System.Windows.Forms.StatusBarPanel
        Me.m_panel_main = New System.Windows.Forms.Panel
        Me.m_fg = New C1.Win.C1FlexGrid.C1FlexGrid
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.m_lbl_last_updated_user = New System.Windows.Forms.Label
        Me.m_lbl_last_updated_date = New System.Windows.Forms.Label
        Me.m_lbl_created_date = New System.Windows.Forms.Label
        Me.m_lbl_created_user = New System.Windows.Forms.Label
        Me.m_txt_date_created = New System.Windows.Forms.TextBox
        Me.m_txt_last_updated_user = New System.Windows.Forms.TextBox
        Me.m_txt_user_created = New System.Windows.Forms.TextBox
        Me.m_txt_last_updated_date = New System.Windows.Forms.TextBox
        Me.m_lbl_info = New System.Windows.Forms.Label
        Me.m_panel.SuspendLayout()
        CType(Me.m_stMess, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.m_stUser, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.m_panel_main.SuspendLayout()
        CType(Me.m_fg, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'imageList
        '
        Me.imageList.ImageStream = CType(resources.GetObject("imageList.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.imageList.TransparentColor = System.Drawing.Color.Transparent
        Me.imageList.Images.SetKeyName(0, "")
        Me.imageList.Images.SetKeyName(1, "")
        Me.imageList.Images.SetKeyName(2, "")
        Me.imageList.Images.SetKeyName(3, "")
        Me.imageList.Images.SetKeyName(4, "")
        Me.imageList.Images.SetKeyName(5, "")
        Me.imageList.Images.SetKeyName(6, "")
        Me.imageList.Images.SetKeyName(7, "")
        Me.imageList.Images.SetKeyName(8, "")
        Me.imageList.Images.SetKeyName(9, "")
        '
        'm_panel
        '
        Me.m_panel.Controls.Add(Me.m_cmd_them_moi)
        Me.m_panel.Controls.Add(Me.m_cmd_chi_tiet)
        Me.m_panel.Controls.Add(Me.m_cmd_xoa)
        Me.m_panel.Controls.Add(Me.m_cmd_thoat)
        Me.m_panel.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.m_panel.Location = New System.Drawing.Point(0, 479)
        Me.m_panel.Name = "m_panel"
        Me.m_panel.Padding = New System.Windows.Forms.Padding(4)
        Me.m_panel.Size = New System.Drawing.Size(768, 40)
        Me.m_panel.TabIndex = 21
        '
        'm_cmd_them_moi
        '
        Me.m_cmd_them_moi.AdjustImageLocation = New System.Drawing.Point(0, 0)
        Me.m_cmd_them_moi.BtnShape = SIS.Controls.Button.emunType.BtnShape.Rectangle
        Me.m_cmd_them_moi.BtnStyle = SIS.Controls.Button.emunType.XPStyle.[Default]
        Me.m_cmd_them_moi.Dock = System.Windows.Forms.DockStyle.Right
        Me.m_cmd_them_moi.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.m_cmd_them_moi.ImageIndex = 9
        Me.m_cmd_them_moi.ImageList = Me.imageList
        Me.m_cmd_them_moi.Location = New System.Drawing.Point(452, 4)
        Me.m_cmd_them_moi.Name = "m_cmd_them_moi"
        Me.m_cmd_them_moi.Size = New System.Drawing.Size(80, 32)
        Me.m_cmd_them_moi.TabIndex = 17
        Me.m_cmd_them_moi.Text = "&Thêm"
        '
        'm_cmd_chi_tiet
        '
        Me.m_cmd_chi_tiet.AdjustImageLocation = New System.Drawing.Point(0, 0)
        Me.m_cmd_chi_tiet.BtnShape = SIS.Controls.Button.emunType.BtnShape.Rectangle
        Me.m_cmd_chi_tiet.BtnStyle = SIS.Controls.Button.emunType.XPStyle.[Default]
        Me.m_cmd_chi_tiet.Dock = System.Windows.Forms.DockStyle.Right
        Me.m_cmd_chi_tiet.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.m_cmd_chi_tiet.ImageIndex = 1
        Me.m_cmd_chi_tiet.ImageList = Me.imageList
        Me.m_cmd_chi_tiet.Location = New System.Drawing.Point(532, 4)
        Me.m_cmd_chi_tiet.Name = "m_cmd_chi_tiet"
        Me.m_cmd_chi_tiet.Size = New System.Drawing.Size(72, 32)
        Me.m_cmd_chi_tiet.TabIndex = 19
        Me.m_cmd_chi_tiet.Text = "C&hi tiết"
        '
        'm_cmd_xoa
        '
        Me.m_cmd_xoa.AdjustImageLocation = New System.Drawing.Point(0, 0)
        Me.m_cmd_xoa.BtnShape = SIS.Controls.Button.emunType.BtnShape.Rectangle
        Me.m_cmd_xoa.BtnStyle = SIS.Controls.Button.emunType.XPStyle.[Default]
        Me.m_cmd_xoa.Dock = System.Windows.Forms.DockStyle.Right
        Me.m_cmd_xoa.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.m_cmd_xoa.ImageIndex = 4
        Me.m_cmd_xoa.ImageList = Me.imageList
        Me.m_cmd_xoa.Location = New System.Drawing.Point(604, 4)
        Me.m_cmd_xoa.Name = "m_cmd_xoa"
        Me.m_cmd_xoa.Size = New System.Drawing.Size(72, 32)
        Me.m_cmd_xoa.TabIndex = 18
        Me.m_cmd_xoa.Text = "&Xoá "
        '
        'm_cmd_thoat
        '
        Me.m_cmd_thoat.AdjustImageLocation = New System.Drawing.Point(0, 0)
        Me.m_cmd_thoat.BtnShape = SIS.Controls.Button.emunType.BtnShape.Rectangle
        Me.m_cmd_thoat.BtnStyle = SIS.Controls.Button.emunType.XPStyle.[Default]
        Me.m_cmd_thoat.Dock = System.Windows.Forms.DockStyle.Right
        Me.m_cmd_thoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.m_cmd_thoat.ImageIndex = 6
        Me.m_cmd_thoat.ImageList = Me.imageList
        Me.m_cmd_thoat.Location = New System.Drawing.Point(676, 4)
        Me.m_cmd_thoat.Name = "m_cmd_thoat"
        Me.m_cmd_thoat.Size = New System.Drawing.Size(88, 32)
        Me.m_cmd_thoat.TabIndex = 15
        Me.m_cmd_thoat.Text = "&Thoát"
        Me.m_cmd_thoat.Visible = False
        '
        'm_stb_fms_style
        '
        Me.m_stb_fms_style.ImeMode = System.Windows.Forms.ImeMode.NoControl
        Me.m_stb_fms_style.Location = New System.Drawing.Point(0, 519)
        Me.m_stb_fms_style.Name = "m_stb_fms_style"
        Me.m_stb_fms_style.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.m_stMess, Me.m_stUser})
        Me.m_stb_fms_style.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.m_stb_fms_style.ShowPanels = True
        Me.m_stb_fms_style.Size = New System.Drawing.Size(768, 22)
        Me.m_stb_fms_style.TabIndex = 22
        Me.m_stb_fms_style.Text = "statusBar"
        '
        'm_stMess
        '
        Me.m_stMess.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring
        Me.m_stMess.Icon = CType(resources.GetObject("m_stMess.Icon"), System.Drawing.Icon)
        Me.m_stMess.Name = "m_stMess"
        Me.m_stMess.Width = 720
        '
        'm_stUser
        '
        Me.m_stUser.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents
        Me.m_stUser.Icon = CType(resources.GetObject("m_stUser.Icon"), System.Drawing.Icon)
        Me.m_stUser.Name = "m_stUser"
        Me.m_stUser.Width = 31
        '
        'm_panel_main
        '
        Me.m_panel_main.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.m_panel_main.Controls.Add(Me.m_fg)
        Me.m_panel_main.Controls.Add(Me.Panel1)
        Me.m_panel_main.Controls.Add(Me.m_lbl_info)
        Me.m_panel_main.Dock = System.Windows.Forms.DockStyle.Fill
        Me.m_panel_main.Location = New System.Drawing.Point(0, 0)
        Me.m_panel_main.Name = "m_panel_main"
        Me.m_panel_main.Size = New System.Drawing.Size(768, 479)
        Me.m_panel_main.TabIndex = 25
        '
        'm_fg
        '
        Me.m_fg.AllowAddNew = True
        Me.m_fg.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.Rows
        Me.m_fg.ColumnInfo = resources.GetString("m_fg.ColumnInfo")
        Me.m_fg.Dock = System.Windows.Forms.DockStyle.Fill
        Me.m_fg.KeyActionEnter = C1.Win.C1FlexGrid.KeyActionEnum.MoveAcross
        Me.m_fg.Location = New System.Drawing.Point(0, 38)
        Me.m_fg.Name = "m_fg"
        Me.m_fg.Rows.Count = 43
        Me.m_fg.Size = New System.Drawing.Size(764, 382)
        Me.m_fg.Styles = New C1.Win.C1FlexGrid.CellStyleCollection(resources.GetString("m_fg.Styles"))
        Me.m_fg.TabIndex = 24
        '
        'Panel1
        '
        Me.Panel1.Controls.Add(Me.m_lbl_last_updated_user)
        Me.Panel1.Controls.Add(Me.m_lbl_last_updated_date)
        Me.Panel1.Controls.Add(Me.m_lbl_created_date)
        Me.Panel1.Controls.Add(Me.m_lbl_created_user)
        Me.Panel1.Controls.Add(Me.m_txt_date_created)
        Me.Panel1.Controls.Add(Me.m_txt_last_updated_user)
        Me.Panel1.Controls.Add(Me.m_txt_user_created)
        Me.Panel1.Controls.Add(Me.m_txt_last_updated_date)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.Panel1.Location = New System.Drawing.Point(0, 420)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(764, 55)
        Me.Panel1.TabIndex = 26
        '
        'm_lbl_last_updated_user
        '
        Me.m_lbl_last_updated_user.Location = New System.Drawing.Point(4, 28)
        Me.m_lbl_last_updated_user.Name = "m_lbl_last_updated_user"
        Me.m_lbl_last_updated_user.Size = New System.Drawing.Size(84, 20)
        Me.m_lbl_last_updated_user.TabIndex = 9
        Me.m_lbl_last_updated_user.Text = "Người sửa cuối"
        Me.m_lbl_last_updated_user.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'm_lbl_last_updated_date
        '
        Me.m_lbl_last_updated_date.Location = New System.Drawing.Point(10, 6)
        Me.m_lbl_last_updated_date.Name = "m_lbl_last_updated_date"
        Me.m_lbl_last_updated_date.Size = New System.Drawing.Size(78, 20)
        Me.m_lbl_last_updated_date.TabIndex = 8
        Me.m_lbl_last_updated_date.Text = "Ngày sửa cuối"
        Me.m_lbl_last_updated_date.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'm_lbl_created_date
        '
        Me.m_lbl_created_date.Location = New System.Drawing.Point(490, 6)
        Me.m_lbl_created_date.Name = "m_lbl_created_date"
        Me.m_lbl_created_date.Size = New System.Drawing.Size(72, 20)
        Me.m_lbl_created_date.TabIndex = 7
        Me.m_lbl_created_date.Text = "Người tạo"
        Me.m_lbl_created_date.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'm_lbl_created_user
        '
        Me.m_lbl_created_user.Location = New System.Drawing.Point(506, 28)
        Me.m_lbl_created_user.Name = "m_lbl_created_user"
        Me.m_lbl_created_user.Size = New System.Drawing.Size(56, 20)
        Me.m_lbl_created_user.TabIndex = 6
        Me.m_lbl_created_user.Text = "Ngày tạo"
        Me.m_lbl_created_user.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'm_txt_date_created
        '
        Me.m_txt_date_created.Enabled = False
        Me.m_txt_date_created.Location = New System.Drawing.Point(576, 28)
        Me.m_txt_date_created.Name = "m_txt_date_created"
        Me.m_txt_date_created.Size = New System.Drawing.Size(188, 20)
        Me.m_txt_date_created.TabIndex = 4
        Me.m_txt_date_created.Text = "m_date_created"
        '
        'm_txt_last_updated_user
        '
        Me.m_txt_last_updated_user.BackColor = System.Drawing.SystemColors.HighlightText
        Me.m_txt_last_updated_user.Enabled = False
        Me.m_txt_last_updated_user.ForeColor = System.Drawing.SystemColors.WindowText
        Me.m_txt_last_updated_user.Location = New System.Drawing.Point(94, 28)
        Me.m_txt_last_updated_user.Name = "m_txt_last_updated_user"
        Me.m_txt_last_updated_user.ReadOnly = True
        Me.m_txt_last_updated_user.Size = New System.Drawing.Size(178, 20)
        Me.m_txt_last_updated_user.TabIndex = 3
        Me.m_txt_last_updated_user.Text = "m_txt_last_updated_user"
        '
        'm_txt_user_created
        '
        Me.m_txt_user_created.Enabled = False
        Me.m_txt_user_created.Location = New System.Drawing.Point(576, 6)
        Me.m_txt_user_created.Name = "m_txt_user_created"
        Me.m_txt_user_created.Size = New System.Drawing.Size(188, 20)
        Me.m_txt_user_created.TabIndex = 2
        Me.m_txt_user_created.Text = "m_user_created"
        '
        'm_txt_last_updated_date
        '
        Me.m_txt_last_updated_date.Enabled = False
        Me.m_txt_last_updated_date.ForeColor = System.Drawing.SystemColors.WindowText
        Me.m_txt_last_updated_date.Location = New System.Drawing.Point(94, 6)
        Me.m_txt_last_updated_date.Name = "m_txt_last_updated_date"
        Me.m_txt_last_updated_date.Size = New System.Drawing.Size(178, 20)
        Me.m_txt_last_updated_date.TabIndex = 1
        Me.m_txt_last_updated_date.Text = "m_txt_last_updated_date"
        '
        'm_lbl_info
        '
        Me.m_lbl_info.Dock = System.Windows.Forms.DockStyle.Top
        Me.m_lbl_info.Font = New System.Drawing.Font("Arial", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.m_lbl_info.Image = CType(resources.GetObject("m_lbl_info.Image"), System.Drawing.Image)
        Me.m_lbl_info.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.m_lbl_info.Location = New System.Drawing.Point(0, 0)
        Me.m_lbl_info.Name = "m_lbl_info"
        Me.m_lbl_info.Size = New System.Drawing.Size(764, 38)
        Me.m_lbl_info.TabIndex = 25
        Me.m_lbl_info.Text = "Quản lý người sử dụng hệ thống School Management"
        Me.m_lbl_info.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'f114_quan_ly_user
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(768, 541)
        Me.Controls.Add(Me.m_panel_main)
        Me.Controls.Add(Me.m_panel)
        Me.Controls.Add(Me.m_stb_fms_style)
        Me.Name = "f114_quan_ly_user"
        Me.Text = "M114 - Quan ly nguoi su dung"
        Me.m_panel.ResumeLayout(False)
        CType(Me.m_stMess, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.m_stUser, System.ComponentModel.ISupportInitialize).EndInit()
        Me.m_panel_main.ResumeLayout(False)
        CType(Me.m_fg, System.ComponentModel.ISupportInitialize).EndInit()
        Me.Panel1.ResumeLayout(False)
        Me.Panel1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region "Public"
    Public Sub display_maintain_users()
        Me.ShowDialog()
    End Sub

    Public Sub display_in_panel() Implements I_DisplayableInPanel.display_in_panel
        Me.Show()
    End Sub

#End Region

#Region "Data Structures"
    Private Enum e_colnumber
        ma_user = 1
        trang_thai = 2
        ten_that = 3
        id = 4
    End Enum

    Private Enum e_TreeLevel
        UserGroup = 0
        User = 1
    End Enum
#End Region

#Region "Members"
    Private m_ds_usergroup As DS_HT_NHOM_NGUOI_SU_DUNG
    Private m_ds_users As DS_HT_NGUOI_SU_DUNG
    Private m_obj_transfer As ITransferDataRow

#End Region


#Region "Private Routines"


    Private Function get_trans_obj() As ITransferDataRow
        Dim v_hasttable As New Hashtable
        v_hasttable.Add(HT_NGUOI_SU_DUNG.ID, e_colnumber.id)
        v_hasttable.Add(HT_NGUOI_SU_DUNG.TEN_THAT, e_colnumber.ten_that)
        v_hasttable.Add(HT_NGUOI_SU_DUNG.TEN_TRUY_CAP, e_colnumber.ma_user)
        v_hasttable.Add(HT_NGUOI_SU_DUNG.TRANG_THAI_NGUOI_SU_DUNG, e_colnumber.trang_thai)

        Dim v_ds_ht_nguoi_su_dung_row As DataRow = (New DS_HT_NGUOI_SU_DUNG).HT_NGUOI_SU_DUNG.NewRow
        Dim v_obj_trans As New CC1TransferDataRow(m_fg, v_hasttable, v_ds_ht_nguoi_su_dung_row)
        Return v_obj_trans
    End Function

    Private Sub set_field_disable(ByVal i_textbox As TextBox)
        i_textbox.Enabled = False
        i_textbox.BackColor = System.Drawing.Color.White
        i_textbox.ForeColor = System.Drawing.Color.Black
    End Sub

    Private Sub format_controls()
        'CControlFormat.setFormStyle(Me, New CApplicationContext, IPFormStyle.DialogForm)
        CControlFormat.setFormStyle(Me, IPFormStyle.DialogForm)
        CControlFormat.setC1FlexFormat(m_fg, C1GridStyle.GridViewAndSearch)
        'CControlFormat.setLabelStyle(m_lbl_info, LabelStyle.HighLight_Info)
        CControlFormat.setLabelStyle(m_lbl_created_date, LabelStyle.Prompt_Info)
        CControlFormat.setLabelStyle(m_lbl_created_user, LabelStyle.Prompt_Info)
        CControlFormat.setLabelStyle(m_lbl_last_updated_date, LabelStyle.Prompt_Info)
        CControlFormat.setLabelStyle(m_lbl_last_updated_user, LabelStyle.Prompt_Info)
        m_fg.AllowSorting = AllowSortingEnum.None
        m_fg.AllowDragging = AllowDraggingEnum.None
        m_fg.Tree.Column = e_colnumber.ma_user
        m_fg.Tree.Style = TreeStyleFlags.SimpleLeaf
        CGridUtils.AddSearch_Handlers(m_fg)
        CGridUtils.AddSave_Excel_Handlers(m_fg)
        set_field_disable(m_txt_last_updated_user)
        set_field_disable(m_txt_last_updated_date)

        'add handlers
    End Sub



    Private Sub load_data_2_datasets()
        Dim v_us_usergroup As New US_HT_NHOM_NGUOI_SU_DUNG
        Dim v_us_users As New US_HT_NGUOI_SU_DUNG
        Try
            v_us_usergroup.open_connection()
            m_ds_usergroup = New DS_HT_NHOM_NGUOI_SU_DUNG
            v_us_usergroup.FillDataset(m_ds_usergroup)
            v_us_users.continue_connection_of(v_us_usergroup)
            m_ds_users = New DS_HT_NGUOI_SU_DUNG
            v_us_users.FillDataset(m_ds_users)
            v_us_usergroup.commit_close_connection()
        Catch v_ex As Exception
            v_us_usergroup.rollback_close_connection()
            CExpUtils.DefaultDBExpHandler(v_ex)

        End Try

    End Sub

    Private Sub display_row_additional_data(ByVal i_grid_row_index As Integer)
        If Not CGridUtils.isValid_NonFixed_RowIndex(m_fg, i_grid_row_index) Then Exit Sub

        If m_fg.Rows(i_grid_row_index).Node.Level = e_TreeLevel.User Then
            Dim v_dr As DataRow = CType(m_fg.Rows(i_grid_row_index).UserData, DataRow)
            Dim v_us_user As New US_HT_NGUOI_SU_DUNG
            v_us_user.DataRow2Me(v_dr)
            If v_us_user.IsCREATED_DATENull() Then
                m_txt_date_created.Text = ""
            Else
                m_txt_date_created.Text = CIPConvert.ToStr(v_us_user.datCREATED_DATE)
            End If

            If v_us_user.IsCREATED_BYNull Then
                m_txt_user_created.Text = ""
            Else
                m_txt_user_created.Text = v_us_user.strCREATED_BY
            End If
            If v_us_user.IsUPDATED_BYNull Then
                m_txt_last_updated_user.Text = ""
            Else
                m_txt_last_updated_user.Text = v_us_user.strUPDATED_BY
            End If

            If v_us_user.IsUPDATED_DATENull() Then
                m_txt_last_updated_date.Text = ""
            Else
                m_txt_last_updated_date.Text = CIPConvert.ToStr(v_us_user.datUPDATED_DATE)
            End If
        Else
            m_txt_date_created.Text = ""
            m_txt_last_updated_date.Text = ""
            m_txt_last_updated_user.Text = ""
            m_txt_user_created.Text = ""
        End If
    End Sub
    Private Function get_user_datarows_in_group(ByVal i_dc_id_usergroup As Decimal) As DataView
        Return New DataView(m_ds_users.HT_NGUOI_SU_DUNG, _
                                      HT_NGUOI_SU_DUNG.ID_NHOM_NGUOI_SU_DUNG & "  =  " & i_dc_id_usergroup.ToString, _
                                      "ID", DataViewRowState.CurrentRows)
    End Function
    Private Sub load_data_2_grid()

        Try
            RemoveHandler m_fg.AfterRowColChange, AddressOf Me.m_fg_AfterRowColChange
            m_fg.Redraw = False
            CGridUtils.ClearDataInGrid(m_fg)

            m_obj_transfer = get_trans_obj()
            Dim v_dr_usergroup As DataRow
            Dim v_i_row_index As Integer = m_fg.Rows.Fixed
            For Each v_dr_usergroup In m_ds_usergroup.HT_NHOM_NGUOI_SU_DUNG.Rows
                m_fg.Rows.Add()
                m_fg(v_i_row_index, e_colnumber.ma_user) = v_dr_usergroup(HT_NHOM_NGUOI_SU_DUNG.MA_NHOM).ToString() & " - " & v_dr_usergroup(HT_NHOM_NGUOI_SU_DUNG.GHI_CHU).ToString()
                m_fg.Rows(v_i_row_index).UserData = v_dr_usergroup
                m_fg.Rows(v_i_row_index).IsNode = True
                m_fg.Rows(v_i_row_index).Node.Level = e_TreeLevel.UserGroup
                v_i_row_index += 1
                'user in this group
                Dim v_dr_user As DataRowView
                Dim v_id_usergroup As Decimal = New Decimal(CType(v_dr_usergroup(HT_NHOM_NGUOI_SU_DUNG.ID), Double))
                For Each v_dr_user In get_user_datarows_in_group(v_id_usergroup)

                    m_fg.Rows.Add()
                    m_fg.Rows(v_i_row_index).UserData = v_dr_user.Row
                    m_obj_transfer.DataRow2GridRow(v_dr_user.Row, v_i_row_index)
                    m_fg.Rows(v_i_row_index).IsNode = True
                    m_fg.Rows(v_i_row_index).Node.Level = e_TreeLevel.User
                    v_i_row_index += 1
                Next
            Next
        Catch v_ex As Exception
            Throw v_ex
        Finally
            m_fg.Redraw = True
            AddHandler m_fg.AfterRowColChange, AddressOf Me.m_fg_AfterRowColChange
        End Try

    End Sub
    Private Sub load_initial_data()
        load_data_2_datasets()
        load_data_2_grid()
    End Sub

    Private Sub set_form_initial()
        AddHandler m_cmd_them_moi.Click, AddressOf Me.m_cmd_them_moi_Click
        AddHandler m_cmd_chi_tiet.Click, AddressOf Me.m_cmd_chi_tiet_Click
    End Sub
    Private Function is_user_row(ByVal i_index As Integer) As Boolean
        If Not CGridUtils.isValid_NonFixed_RowIndex(m_fg, i_index) Then Return False
        Return m_fg.Rows(i_index).Node.Level = e_TreeLevel.User
    End Function

    Private Sub grid_row_2_user_us_object(ByVal i_index As Integer, ByVal i_us As US_HT_NGUOI_SU_DUNG)
        If Not CGridUtils.isValid_NonFixed_RowIndex(m_fg, i_index) Then Exit Sub
        If Not Me.is_user_row(i_index) Then Exit Sub
        Dim v_datarow As DataRow = CType(m_fg.Rows(i_index).UserData, DataRow)
        i_us.DataRow2Me(v_datarow)
    End Sub

    Private Sub addnew_user()
        Dim v_frm As New f115_quan_ly_user_de
        v_frm.addnew_user(m_ds_users)
        load_data_2_grid()
    End Sub

    Private Sub view_detail_user()
        If Not is_user_row(m_fg.Row) Then Exit Sub
        Dim v_frm As New f115_quan_ly_user_de
        Dim v_us_user As New US_HT_NGUOI_SU_DUNG
        grid_row_2_user_us_object(m_fg.Row, v_us_user)
        v_frm.view_detail_user(m_ds_users, v_us_user)
        load_data_2_grid()
    End Sub
    Private Sub delete_user()
        If Not is_user_row(m_fg.Row) Then Exit Sub
        If BaseMessages.askUser_DataCouldBeDeleted(8) = BaseMessages.IsDataCouldBeDeleted.ShouldNotBeDeleted Then Exit Sub
        Dim v_us_user As New US_HT_NGUOI_SU_DUNG
        grid_row_2_user_us_object(m_fg.Row, v_us_user)
        Try
            v_us_user.open_connection()
            v_us_user.Delete()
            v_us_user.commit_close_connection()
        Catch ex As Exception
            If v_us_user.is_having_connection() Then
                v_us_user.rollback_close_connection()
            End If
            Throw ex
        End Try
        load_data_2_datasets()
        load_data_2_grid()
    End Sub
#End Region

    '
    'EVENT HANDLERS
    '
    '

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Try
            set_form_initial()
            load_initial_data()
        Catch v_ex As Exception
            CSystemLog_301.ExceptionHandle(v_ex)
        End Try
    End Sub

    Private Sub m_fg_AfterRowColChange(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RangeEventArgs)
        Try
            display_row_additional_data(e.NewRange.r1)
        Catch v_ex As Exception
            CSystemLog_301.ExceptionHandle(v_ex)
        End Try
    End Sub


    Private Sub m_cmd_them_moi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            addnew_user()
        Catch v_ex As Exception
            CSystemLog_301.ExceptionHandle(v_ex)
        End Try
    End Sub

    Private Sub m_cmd_chi_tiet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            view_detail_user()
        Catch v_ex As Exception
            CSystemLog_301.ExceptionHandle(v_ex)
        End Try
    End Sub

    Private Sub m_cmd_thoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_cmd_thoat.Click
        Try
            Me.Close()

        Catch v_ex As Exception
            CSystemLog_301.ExceptionHandle(v_ex)
        End Try
    End Sub


    Private Sub m_cmd_xoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_cmd_xoa.Click
        Try

            delete_user()
        Catch ex As Exception
            CSystemLog_301.ExceptionHandle(ex)

        End Try
    End Sub
End Class
